package com.rqf.mr.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.rqf.mr.service.IBedService;
import com.rqf.mr.service.IPatientService;
import com.rqf.mr.service.impl.PatientService;
import com.server.web.JSONSerielizer;
import com.server.web.OutputUtil;

/**
 * 床位
 * 
 * @author HelloWorld_luo
 * @date 2016年4月19日
 */
@Controller
@RequestMapping("bed")
public class BedController {

	@Autowired
	private IBedService bedService;
	@Autowired
	private IPatientService patientService;

	@RequestMapping("getlist/{nurseLoginId}/{field}/{type}/{value}")
	public void getlist(HttpServletRequest request,
			HttpServletResponse response, @PathVariable String field, @PathVariable String nurseLoginId,
			@PathVariable String type, @PathVariable String value) {
		String whereStr = "";
		List<Map<String, Object>> list = null;
		if (type.equals("LIKE")) {
			whereStr = field  + " LIKE'%" + value + "%'";
		}else if (type.equals("dengyu")) {
			whereStr = field  + " = '" + value + "'";
		}
		if (StringUtils.isEmpty(value)||StringUtils.isEmpty(field)||StringUtils.isEmpty(type)) {
			whereStr = "";
		}
		list = bedService.getBedList(nurseLoginId, whereStr);
		String json = JSONSerielizer.toJson(list, null, null);
		OutputUtil.returnJsonp(request, response, json);
	}
	
	@RequestMapping("getNurseBed/{nurseLoginId}")
	public void getNurseBed(HttpServletRequest request,
			HttpServletResponse response, @PathVariable String nurseLoginId) {
		List<Map<String,Object>> list = bedService.getNurseBedList(nurseLoginId);
		String json = JSONSerielizer.toJson(list, null, null);
		OutputUtil.returnJsonp(request, response, json);
	}
	
	@RequestMapping("departmentBed/{nurseLoginId}")
	public void departmentBed(HttpServletRequest request,
			HttpServletResponse response, @PathVariable String nurseLoginId) {
		String page = "";
		List<Map<String,Object>> list = bedService.getTeamedBedInfoByNurseId(nurseLoginId,page);
		String json = JSONSerielizer.toJson(list, null, null);
		OutputUtil.returnJsonp(request, response, json);
	}
	
	@RequestMapping("departmentBed/{nurseLoginId}/{page}")
	public void departmentBedPage(HttpServletRequest request,
			HttpServletResponse response, @PathVariable String nurseLoginId, @PathVariable String page) {
		List<Map<String,Object>> list = bedService.getTeamedBedInfoByNurseId(nurseLoginId,page);
		String json = JSONSerielizer.toJson(list, null, null);
		OutputUtil.returnJsonp(request, response, json);
	}
	
	@RequestMapping("bedPatiDetail/{inpatiId}")
	public void bedPatiDetail(HttpServletRequest request,
			HttpServletResponse response, @PathVariable String inpatiId) {
		Map<String,Object> map = bedService.getBedDetailByInpatiId(inpatiId);
		String json = JSONSerielizer.toJson(map, null, null);
		OutputUtil.returnJsonp(request, response, json);
	}
}
